﻿// owner 蒋家伟

#include "DataCodecUtils.h"

using namespace jsdk;

int32_t jsdk::DataCodecUtils::toInt32(const char* pByteStream)
{
    int32_t temp = 0;
    memcpy((char*)(&temp) + 3, pByteStream, sizeof(char));
    memcpy((char*)(&temp) + 2, pByteStream +1 , sizeof(char));
    memcpy((char*)(&temp) + 1, pByteStream +2 , sizeof(char));
    memcpy(&temp, pByteStream + 3, sizeof(char));
    return temp;
}

int8_t jsdk::DataCodecUtils::toInt8(const char* pByteStream)
{
    int8_t temp = 0;
    memcpy(&temp, pByteStream, sizeof(char));
    return temp;
}


int16_t jsdk::DataCodecUtils::toInt16_t(const char* pByteStream)
{
    int16_t temp = 0;
    memcpy((char*)(&temp) + 1, pByteStream, sizeof(char));
    memcpy((char*)(&temp), pByteStream + 1, sizeof(char));
    return temp;
}

float jsdk::DataCodecUtils::toFloat(const char* pByteStream)
{
    float temp = 0;
    memcpy((char*)(&temp) + 3, pByteStream, sizeof(char));
    memcpy((char*)(&temp) + 2, pByteStream + 1, sizeof(char));
    memcpy((char*)(&temp) + 1, pByteStream + 2, sizeof(char));
    memcpy(&temp, pByteStream + 3, sizeof(char));
    return temp;
}
